//注册界面JavaScript
$(function(){
	//easyui实现省市区三级联动
	$("#province").combobox({  
        editable:false, //不可编辑状态  
        cache: false,
        //panelHeight:'auto',
        valueField:"code",     
        textField:"note",  
        url: '/User/LoadArea',
        onHidePanel: function(){  
            $("#city").combobox("setValue",'');  
            $("#county").combobox("setValue",'');  
            $("#cregicounty").val('');  
            
            var province = $('#province').combobox('getValue');       
            if(province!=''){
            
            $.ajax({
        		type:'post',
        			url : "/User/LoadCity?province="+province,
        			async : true,
        			dataType:'json',
        			success : function(data) {
        				$("#city").combobox("loadData",data); 
        			},
        
        		});
            }; 
         }
	});
	
	
	$("#city").combobox({
		editable:false, //不可编辑状态  
        cache: false,  
        //panelHeight: 'auto',//自动高度适合  
        valueField:'code',     
        textField:'note',  
        onHidePanel: function(){  
            $("#cregicounty").val('');  
            $("#county").combobox("setValue",'');  
            var city = $('#city').combobox('getValue');       
            if(city!=''){  
            $.ajax({  
                type: "POST",  
                url: "/User/LoadCounty?city="+city,  
                cache: false,  
                dataType : "json",  
                success: function(data){  
                $("#county").combobox("loadData",data);  
                                       }  
                                   });    
                           }  
                     }  
		
	});
	
	$("#county").combobox({
		editable:false, //不可编辑状态  
        cache: false,  
        // panelHeight: 'auto',//自动高度适合  
        valueField:'code',     
        textField:'note',  
        
        onHidePanel: function(){  
        var str=$('#county').combobox('getText');  
        if(str!=""){
        alert(str);	
        };
        }
	});
	
	
	//在线验证用户名
	$("#usr").blur(function() {
		var username = $("#usr").val();
		if(username!=""){
		$.ajax({
		type:'post',
			url : "/User/checkName?username=" + username,
			async : true,
			dataType:'text',
			success : function(data) {
			//debugger;
			$("#ckusr").html(data); 
			}
		});
		};
	});
	
	//显示密码强度
	$("#passwd").keyup(function() {
 	var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
 	var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
 	var enoughRegex = new RegExp("(?=.{6,}).*", "g");
 	if (false == enoughRegex.test($(this).val())) {
         $('#passstrength').html('More Characters');
         $("#passstrengthshow").html('<img src="img/nochar.jpg"/>');
 	} else if (strongRegex.test($(this).val())) {
         $('#passstrength').className = 'ok';
         $('#passstrength').html('Strong!');
         $("#passstrengthshow").html('<img src="img/strong.jpg"/>');
 	} else if (mediumRegex.test($(this).val())) {
         $('#passstrength').className = 'alert';
         $('#passstrength').html('Medium!');
         $("#passstrengthshow").html('<img src="img/mediu.jpg"/>');
 	} else {
         $('#passstrength').className = 'error';
         $('#passstrength').html('Weak!');
         $("#passstrengthshow").html('<img src="img/weak.jpg"/>');
 	}
 	return true;
});
	
//验证再次输入密码
$("#passwd1").blur(function() {
		var password = $("#passwd").val();
		var password1 = $("#passwd1").val();
		if(password1!=password){
		alert("前后两次密码不一致");
		};
	});
//验证其他
$("#email").blur(function() {
var email=$("#email").val();
var patt1=new RegExp("@");

if(!patt1.test(email)){
	alert("电子邮箱格式不正确，请重新输入");
};
});


});

/*
//使用ajax实现的
function ckUser() {
	var xmlhttp;
	var username = document.getElementById("usr").value;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();

	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

	}

	//使用回调函数实现的
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//debugger;
			document.getElementById("ckusr").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.open("POST", "/User/checkName", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.send("username=" + username);
}
*/